<template>
  <van-cell title="123" class="comment-item">
    <van-image class="avatar" round fit="cover" :src="commnet.aut_phtoto" />
    <div slot="title">
      <div class="title-wrap">
        <div class="name">{{ comment.aut_name }}</div>
        <div class="like-wrap" @click="onCommentLike">
          <van-icon
            class="like-icon"
            :class="{ liked: comment.is_liking }"
            :name="comment.is_liking ? 'good-iob' : 'good-job-o'"
            
          />
          <span class="like-count">12</span>
        </div>
      </div>

      <div class="content">{{ comment.content }}</div>
      <div>
        <span class="pubdate">{{ comment.pubdate | datetime }}</span>
        <van-button class="reply-btn" round size="mini">回复</van-button>
      </div>
    </div>
  </van-cell>
</template>
<script>
import { addCommentLike, deleteCommentLike } from "@/api/comment";
export default {
  name: "CommentItem",
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  methods: {
    async onCommentLike() {
        const commentId=this.comment.com_id.toString()
      // 如果已经赞了则取消点赞
      if (this.comment.is_liking) {
        await deleteCommentLike(commentId);
        this.comment.like_count--
      } else {
        // 如果没有赞，则点赞
        await addCommentLike(commentId);
        this.comment.like_count++
      }
      // 更新视图状态
      this.comment.is_liking = !this.comment.is_liking;
    }
  }
}
</script>
<style lang="less" scoped>
.comment-item {
  .avatar {
    width: 36px;
    height: 36px;
    margin-right: 13px;
  }
  .name {
    font-size: 14px;
    color: #406599;
  }
  .content {
    font-size: 16px;
    color: #222222;
  }
  .pubdate {
    font-size: 10px;
    margin-right: 10px;
  }
  .title-wrap {
    display: flex;
    justify-content: space-between;
  }
  .like-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .like-icon.liked {
    color: #ff69b4;
  }
}
</style>